package api

import (
	v1 "jmicro/app/jshop/api/internal/controller/v1"
	"jmicro/app/pkg/options"
	"jmicro/jmicro/core/trace"
	"jmicro/jmicro/server/restserver"
)

func NewAPIHTTPServer(options *options.ServerOptions, tltCfg *options.TelemetryOptions, jwt *options.JwtOptions, store v1.UsersStore) (*restserver.Server, error) {
	trace.InitAgent(trace.Options{
		tltCfg.Name,
		tltCfg.Endpoint,
		tltCfg.Sampler,
		tltCfg.Batcher,
	})
	aRestServer := restserver.NewServer(
		restserver.WithPort(options.HttpPort),
		restserver.WithMiddlewares(options.Middlewares),
		restserver.WithEnableProfiling(true),
		restserver.WithMetrics(true),
	)

	//配置好路由
	initRouter(aRestServer, jwt, store)
	return aRestServer, nil
}
